<?php
    $this->headLink()->prependStylesheet($this->LocateFile('cart.css'));
    $taxFed = 0;
    if(!empty($this->parameters['taxeFed']))
        $taxFed = $this->parameters['taxeFed'];

    $cartTotalCount = $this->cartTotal;
    $url            = $this->baseUrl() . '/' . 'cart/index/ajax/';
?>

<?php $this->headLink()->appendStylesheet(
            $this->locateFile('cart.css'),
            'all');
?>
<?php $this->jQuery()->addJavascriptFile(
            $this->locateFile('jquery.numeric.js','jquery')
    );
    $this->jQuery()->addJavascriptFile(
            $this->locateFile('jsAddToCart.js')
    );
?>

<?php $this->jQuery()->onLoadCaptureStart() ?>
    var baseUrl = "<?php echo $this->baseUrl() ?>";
    defaultProperties.setBaseUrl(baseUrl);
    var langId    = '<?php echo Zend_Registry::get('languageID')?>';
    var taxProv   = '<?php echo $this->parameters['taxeProv']; ?>';

    var taxFed    = '<?php echo $taxFed; ?>';
    var nbPoint   = '<?php echo $this->parameters['nbPoint']; ?>';
    var shipFee   = '<?php echo $this->parameters['tpsFee']; ?>';
    var limitShip = '<?php echo $this->parameters['limitTpsFee']; ?>';

    defaultProperties.setTps(taxFed);
    defaultProperties.setTvq(taxProv);
    defaultProperties.setNbPoint(nbPoint);
    defaultProperties.setShipFee(shipFee);
    defaultProperties.setLimitShip(limitShip);


    $('a.descrLink').click(function() {
        modalWindow.display($(this), langId);
    });
    $('a.chartLink').click(function() {
        modalWindow.display($(this), langId);
    });

    //Close Popups and Fade Layer
    $('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
        modalWindow.close();
    });
    cartActions.calculate();
        
    $("input.quantity").numeric();

    $('input.quantity').live('keyup', function(){
        var baseUrl = "<?php echo $this->baseUrl() ?>";
        var nbField = $(this).parents('div.items-with-border-bottom').children('div').length;
        var qty     = $(this).val();
        idsData     = ($(this).attr('id')).split("-");

        defaultProperties.init(baseUrl, $(this), idsData, 'update', null, null);
        cartActions.ajax();
        
        if (qty != '' && qty == 0)
        {
            cartActions.removeLine();
            location.reload();
        }

    });

    $('a.delete').click(function(){
        var idsData  = ($(this).attr('id')).split("-");
        defaultProperties.init(baseUrl, $(this), idsData, 'delete', null, null);
        cartActions.ajax();
        cartActions.removeLine();
        location.reload();
    });

    $('input').blur(function(){
        location.reload();
    });

<?php $this->jQuery()->onLoadCaptureEnd() ?>

<?php $this->headScript()->captureEnd() ?>
    
<div id="cart" class="block">
    <input type="hidden" id="userTaxProv" name="userTaxProv" value="<?php echo $this->parameters['noProvTax']; ?>"/>
    <input type="hidden" id="userTaxFed" name="userTaxFed" value="<?php echo $this->parameters['noFedTax']; ?>"/>
    <?php if(!empty($this->productData)): ?>
        <?php 
        echo $this->partial('partials/stepTopLine.phtml', array('step' => $this->step));
        ?>
        
        <?php echo $this->partial(
                'partials/cartNavigationLinks.phtml',
                array(
                    'urlBack'   => $this->urlBack,
                    'itemCount' => $this->itemCount,
                    'nextStep'  => $this->nextStep,
                    'step'      => $this->step
                    )
                );
        ?>
        <div id="explication-text">
            <?php echo $this->getClientText('cart_step_'.$this->step.'_explication_text') ?>
        </div>

        <div id="headerProductList">
            <p class="left greenText"><?php echo $this->getClientText('product_label'); ?></p>
            <p class="center greenText"><?php echo $this->getCibleText('form_item_qty_label'); ?></p>
            <p class="middle greenText"><?php echo $this->getClientText('unit_price_label'); ?></p>
            <p class="right greenText"><?php echo $this->getClientText('cart_item_total_label'); ?></p>
        </div>
        <div id="product-list">&nbsp;
        <?php foreach ($this->productData as $cartId => $product):?>
        <?php
            $currProd  = $product['data'];
            $currItem  = $product['items'];
            $productId = $currProd['P_ID'];
            $disable   = $product['cart']['disable'];
            $promo     = $product['cart']['promoId'];
            $itemId    = $currItem['I_ID'];
            $labelPromo = "";


            if (!$disable):

                if($promo > 0)
                    $labelPromo = $this->getClientText('alert_special_offer_item');
        ?>
            <div class="product">
                <div id="dataLeftCol">
                    <div id="image">
                        <?php
                        echo $this->moduleImage(
                            'catalog',
                            'products/' . $productId,
                            $currProd['P_Photo'],
                            'thumb',
                            array(
                                'class'   => 'smallThumb',
                                'alt'     => '',
                                'useSize' => false,
                                'prettyPhoto'=>array(
                                    'size'  => 'original',
                                    'image' => $currProd['P_Photo']
                                    )
                                )
                            );
                        ?>
                    </div>
                    <div class="product-description">
                        <p class="">
                            <?php echo $currProd['PI_Name'] . ' | ' . $currItem['II_Name'] ?>
                            <br /><span class="alertSpecial"><?php echo $labelPromo ; ?></span>
                        </p>
                        <?php echo $this->link(
                            'javascript:void(0);',
                            $this->getClientText('cart_details_action_remove_item'),
                            array(
                                'class'=>'delete',
                                'id'=> 'delete-'. $productId . '-' . $itemId . '-' . $cartId)
                            )
                        ?>
                    </div>
                </div>
                <div id="dataRightCol">
                    <?php
                    echo $currItem['render'];
                    ?>
                </div>
                <div class="clear_both"><?php echo $this->clientImage('pix.gif', array('alt'=>'')); ?></div>
            </div>
        <?php endif; ?>
            <div class="clear_both"><?php echo $this->clientImage('pix.gif', array('alt'=>'')); ?></div>
        <?php endforeach;?>
        </div>
        <div id="totalSummary">
            <div id="pointBoni">
            <?php if($this->parameters['nbPoint']): ?>
                <?php echo $this->getClientText('cart_label_bonus_points'); ?>
            <?php endif; ?>
                <p class="infoTpsFees">
                    <?php echo str_replace('##TP_FEES_LIMIT##', $this->parameters['limitTpsFee'], $this->getClientText('cart_label_tpFees_limit')); ?>
                </p>
                <p class="infoLimitOrder infoTpsFees">
                    <?php echo str_replace('##TP_ORDER_LIMIT##', $this->parameters['limitOrder'], $this->getClientText('cart_label_order_limit')); ?>
                </p>
            </div>
            <div id="summaryContent">
                <p id="zoneTitle" class="blueTxt">
                    <span>
                    <?php echo $this->getClientText('cart_summary_title'); ?>
                    </span>
                </p>
                <p id="subTotalLbl" class="leftCol">
                    <?php echo $this->getClientText('cart_summary_subtotal'); ?>
                </p>
                <p id="subTotalValue" class="rightCol number">
                        <span>0</span> $
                </p>
                <p id="transportLbl" class="leftCol">
                    <?php echo $this->getClientText('cart_transport_label'); ?>
                </p>
                <p id="transportValue" class="rightCol number">
                    <span><?php echo $this->parameters['tpsFee']; ?></span> $
                </p>
                <p id="tvqLbl" class="leftCol">
                    <?php if ($taxFed > 0): ?>
                        <?php echo $this->getClientText('cart_tvq_label'); ?>
                    <?php else: ?>
                        <?php echo $this->parameters['taxeCode']; ?>
                    <?php endif; ?>
                </p>
                <p id="tvqValue"class="rightCol number">
                        <span>0</span> $
                </p>
                <?php if ($taxFed > 0): ?>

                <p id="tpsLbl" class="leftCol">
                    <?php echo $this->getClientText('cart_tps_label'); ?>
                </p>
                <p id="tpsValue" class="rightCol number">
                        <span>0</span> $
                </p>
                <?php endif; ?>
                <p id="totalLbl" class="leftCol blueTxt">
                    <?php echo $this->getClientText('cart_total_label'); ?>
                </p>
                <p id="totalValue" class="rightCol blueTxt"> </p>
            </div>
        </div>
        <?php echo $this->partial(
                'partials/cartNavigationLinks.phtml',
                array(
                    'urlBack'   => $this->urlBack,
                    'itemCount' => $this->itemCount,
                    'nextStep'  => $this->nextStep,
                    'step'      => $this->step
                    )
                );
        ?>

<!--        <div class="clear_both"><?php echo $this->clientImage('pix.gif', array('alt'=>'')); ?></div>-->

        <?php
            $account = Cible_FunctionsGeneral::getAuthentication();
            if( $account && $cartTotalCount ): ?>
            <?php if($this->valide) : ?>
                    <div id="order-now">
                        <?php /*echo $this->link(
                            $this->baseUrl() . '/'
                            . Cible_FunctionsCategories::getPagePerCategoryView(
                                0,
                                'cart_order_form',
                                1001),
                            $this->getClientText('cart_order_continue_link'),
                            array('class'=>'order-button')
                            )*/
                        ?>
                    </div>
            <?php else : ?>
                <div style="margin-top: 20px;">
                    <?php //echo $this->getClientText('cart_need_confirm_email_text'); ?>
                    <?php /*echo($this->link(
                            $this->baseUrl() . '/'
                            . Cible_FunctionsCategories::getPagePerCategoryView(
                                0,
                                'return_confirm_email',
                                1002),
                            $this->getClientText('return_email_confirmation')
                            )
                        );*/
                    ?>
                </div>

            <?php endif;  ?>
        <?php endif; ?>

        <?php if(!$account): ?>

            <span id="login-title">
                <?php //echo $this->getClientText('login_title') ?>
            </span>

        <?php endif; ?>
    <?php else : ?>
        <div id="no-item"><?php echo $this->getClientText('cart_no_item') ?></div>
    <?php endif; ?>
</div>

<!--<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
    $('a.descrLink').click(function() {
        modalWindow.display($(this), langId);
    });
    $('a.chartLink').click(function() {
        modalWindow.display($(this), langId);
    });

    //Close Popups and Fade Layer
    $('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
        modalWindow.close();
    });
    <?php if(isset($currItem)): ?>
        cartActions.calculate();
    <?php endif; ?>

//]]>
});
</script>-->
